#!/bin/sh -
#
# build script for J2ME - this only includes the lightweight API
# if a distribution name is given as an argument the build is placed
# in a subdirectory - nothing gets compiled as we expect the classes
# to be in ./palm
#
# Note: this script expects javadoc for jdk 1.3 to be in your path.
#

base=$1
version=`echo $base | sed -e "s/\([0-9]\)\([0-9a-z]*\)/\1.\2/"`

WINDOWTITLE="Bouncy Castle Cryptography $version API Specification"
HEADER="<b>Bouncy Castle Cryptography $version</b>"
DOCTITLE="Bouncy Castle $version API Specification"

echo "making j2me lightweight release"

if test "$base" != "" 
then
    mkdir lcrypto-j2me-$base
    mkdir lcrypto-j2me-$base/docs
    tar cf - common.xml midp.xml crypto_env.properties index.html LICENSE.html CONTRIBUTORS.html releasenotes.html specifications.html zips src/org/bouncycastle/LICENSE.java src/org/bouncycastle/math \
src/org/bouncycastle/crypto/*.java \
src/org/bouncycastle/crypto/*.html \
src/org/bouncycastle/crypto/agreement \
src/org/bouncycastle/crypto/digests \
src/org/bouncycastle/crypto/encodings \
src/org/bouncycastle/crypto/engines \
src/org/bouncycastle/crypto/examples \
src/org/bouncycastle/crypto/paddings \
src/org/bouncycastle/crypto/generators \
src/org/bouncycastle/crypto/io \
src/org/bouncycastle/crypto/macs \
src/org/bouncycastle/crypto/modes \
src/org/bouncycastle/crypto/params \
src/org/bouncycastle/crypto/signers \
src/org/bouncycastle/crypto/prng \
src/org/bouncycastle/crypto/tls \
src/org/bouncycastle/crypto/util \
src/org/bouncycastle/util \
src/org/bouncycastle/bcpg \
src/org/bouncycastle/asn1 \
src/org/bouncycastle/cert \
src/org/bouncycastle/cms \
src/org/bouncycastle/pkcs \
src/org/bouncycastle/tsp \
src/org/bouncycastle/operator \
src/org/bouncycastle/openpgp \
| (cd lcrypto-j2me-$base; tar xf -)
    (cd test; tar cf - src/org/bouncycastle/crypto/test src/org/bouncycastle/asn1/test | (cd ../lcrypto-j2me-$base; tar xf -))
    (cd j2me; tar cf - * | (cd ../lcrypto-j2me-$base; cd src; tar xf -))
    rm lcrypto-j2me-$base/src/org/bouncycastle/crypto/test/AllTests.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/util/CollectionStore.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/util/StoreException.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/util/Selector.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/util/Store.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/util/StreamParser.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/util/StreamParsingException.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/util/Dump.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/AllTests.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/ASN1SequenceParserTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/AttributeTableUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/BiometricDataUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/BitStringConstantTester.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/CommitmentTypeIndicationUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/CommitmentTypeQualifierUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/DataGroupHashUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/DERUTF8StringTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/EqualsAndHashCodeTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/GeneralizedTimeTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/GenerationTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/InputStreamTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/Iso4217CurrencyCodeUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/KeyUsageTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/LDSSecurityObjectUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/MonetaryValueUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/NameOrPseudonymUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/NetscapeCertTypeTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/OctetStringTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/ParseTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/PersonalDataUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/PKIFailureInfoTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/QCStatementUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/ReasonFlagsTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/SemanticsInformationUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/SetTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/SignerLocationUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/SMIMETest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/TagTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/TypeOfBiometricDataUnitTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/asn1/test/UTCTimeTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/crypto/test/AESVectorFileTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/crypto/test/GCMReorderTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/crypto/test/HCFamilyVecTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/crypto/test/RSABlindedTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/crypto/test/SCryptTest.java
    rm lcrypto-j2me-$base/src/org/bouncycastle/crypto/examples/DESExample.java
    rm -r lcrypto-j2me-$base/src/org/bouncycastle/util/io/pem

    (cd lcrypto-j2me-$base;
        rm -rf src/org/bouncycastle/math/ntru
        rm -rf src/org/bouncycastle/crypto/test/ntru
        rm -rf src/org/bouncycastle/crypto/*/NTRU*
        rm -rf src/org/bouncycastle/crypto/*/BitStringTest*
        rm -rf src/org/bouncycastle/crypto/*/IndexGenerator*
        find src -name AllTests.java -exec rm {} \;
        find src -name jcajce -exec rm -r {} \;
        rm src/org/bouncycastle/asn1/test/GetInstanceTest.java
        rm src/org/bouncycastle/asn1/test/ASN1SequenceParserTest.java
        rm src/org/bouncycastle/asn1/test/OctetStringTest.java
        rm src/org/bouncycastle/asn1/test/ParseTest.java
        rm src/org/bouncycastle/crypto/test/GCMReorderTest.java
    )


   (2>&1 find lcrypto-j2me-$base -name CVS -exec rm -rf \{\} \; ) > /dev/null

    (
    cd lcrypto-j2me-$base;
    javadoc -windowtitle "$WINDOWTITLE" -doctitle "$DOCTITLE" \
      -header "$HEADER" \
    -group "Lightweight Crypto Packages" "org.bouncycastle.crypto*" \
    -group "ASN.1 Support Packages" "org.bouncycastle.asn1*" \
    -group "OpenPGP Support Packages" "org.bouncycastle.bcpg*:org.bouncycastle.openpgp*" \
    -group "Basic Signing And Encryption" "org.bouncycastle.operator*" \
    -group "Certificate Generation And Handling Support Packages" "org.bouncycastle.cert*" \
    -group "CMS Support Packages" "org.bouncycastle.cms*" \
    -group "EAC Support Packages" "org.bouncycastle.eac*" \
    -group "TSP Support Packages" "org.bouncycastle.tsp*" \
    -group "PKCS Support Packages" "org.bouncycastle.pkcs*" \
    -group "Utility Packages" "org.bouncycastle.util*:org.bouncycastle.math*" \
      -classpath classes \
      -d docs -sourcepath src -breakiterator \
    org.bouncycastle.asn1 \
    org.bouncycastle.asn1.cmp \
    org.bouncycastle.asn1.cms \
    org.bouncycastle.asn1.cryptopro \
    org.bouncycastle.asn1.esf \
    org.bouncycastle.asn1.ess \
    org.bouncycastle.asn1.gnu \
    org.bouncycastle.asn1.iana \
    org.bouncycastle.asn1.icao \
    org.bouncycastle.asn1.misc \
    org.bouncycastle.asn1.mozilla \
    org.bouncycastle.asn1.nist \
    org.bouncycastle.asn1.ocsp \
    org.bouncycastle.asn1.oiw \
    org.bouncycastle.asn1.pkcs \
    org.bouncycastle.asn1.sec \
    org.bouncycastle.asn1.smime \
    org.bouncycastle.asn1.teletrust \
    org.bouncycastle.asn1.test \
    org.bouncycastle.asn1.tsp \
    org.bouncycastle.asn1.util \
    org.bouncycastle.asn1.x500 \
    org.bouncycastle.asn1.x500.style \
    org.bouncycastle.asn1.x509 \
    org.bouncycastle.asn1.x9 \
    org.bouncycastle.bcpg \
    org.bouncycastle.bcpg.sig \
    org.bouncycastle.math.ec \
    org.bouncycastle.crypto \
    org.bouncycastle.crypto.agreement \
    org.bouncycastle.crypto.digests \
    org.bouncycastle.crypto.encodings \
    org.bouncycastle.crypto.engines \
    org.bouncycastle.crypto.generators \
    org.bouncycastle.crypto.io \
    org.bouncycastle.crypto.macs \
    org.bouncycastle.crypto.modes \
    org.bouncycastle.crypto.params \
    org.bouncycastle.crypto.paddings \
    org.bouncycastle.crypto.signers \
    org.bouncycastle.crypto.prng \
    org.bouncycastle.crypto.tls \
    org.bouncycastle.crypto.test \
    org.bouncycastle.crypto.util \
    org.bouncycastle.crypto.examples \
    org.bouncycastle.util.encoders \
    org.bouncycastle.util.test > /dev/null \

    )
fi
